from apps.common.base.views import *
from apps.common.wx.wxapi import getOpenid

class WxViewSet(BaseViewSet):

    '''获取openid'''
    @action(methods=['post'], detail=False, authentication_classes=[], permission_classes=[])
    def getOpenId(self, request):
        params = getRequestParams(request)
        if isEmptyStr(params.get('code')):
            return Response(response_message('code参数必填'))
        if isEmptyStr(params.get('clientname')):
            return Response(response_message('clientname参数必填'))
        data = getOpenid(params.get('code'), params.get('clientname'))
        return Response(response_success({'openid': data.get('openid')}))